vpath %.proto src/messages
vpath %.h protoc/cpp
vpath %.cc protoc/cpp
vpath %.hpp inc:libinc
vpath %.cpp src:src/tests
vpath %.o obj

vpath %.a lib
vpath %.exe bin
vpath %.so bin

CPPFLAGS = -Wall -std=c++17 -DWIN32 -Iinc -Ilibinc -Iprotoc/cpp
LDFLAGS = -Llib -lws2_32 -static-libgcc -static-libstdc++ 
CLANGFLAGS = -std=c++17 --target=aarch64-linux-android21 -march=armv8-a -fPIC -O3 \
	-DANDROID_ENABLED -DUNIX_ENABLED -DNDEBUG -Iinc -Ilibinc
CORE_LIBS = -lprotobuf -lmemoryMgr
TEST_LIBS = -lpathbuildercore

./dep/%.pb.d: %.proto
	protoc -I./src/messages --cpp_out=./protoc/cpp $<
	g++ -MM $(CPPFLAGS) ./protoc/cpp/$(*F).pb.cc -o $@
%.pb.o: %.pb.cc
	g++ -c ./protoc/cpp/$(<F) -o ./obj/$@ $(CPPFLAGS) $(LDFLAGS) $(CORE_LIBS)
./dep/%.d: %.cpp
	g++ -MM $(CPPFLAGS) $< -o $@
%.o: %.cpp
	g++ -c $< -o ./obj/$@ $(CPPFLAGS) $(LDFLAGS)

debug: CPPFLAGS += -g
debug: build
release: build
build: libpathbuildercore.a
unit_test: debug unittest.exe
clean:
	rm -f ./obj/*.o

UNITTEST_OBJS := unittest.o
unittest.exe: $(UNITTEST_OBJS) libpathbuildercore.a
	g++ $(addprefix ./obj/, $(UNITTEST_OBJS)) -o ./bin/$@ $(CPPFLAGS) $(LDFLAGS) $(TEST_LIBS) $(CORE_LIBS)

PATHBUILDER_CORE_OBJ := pathBuilder.o voxeldata.pb.o
libpathbuildercore.a: $(PATHBUILDER_CORE_OBJ)
	ar rcs ./lib/$@ $(addprefix ./obj/, $(PATHBUILDER_CORE_OBJ))

MSGSRCS := $(notdir $(shell find ./protoc/cpp -name "*.pb.cc" ) ) 
include $(MSGSRCS:%.pb.cc=./dep/%.pb.d)
SRCS := $(notdir $(shell find ./src -name "*.cpp" ) ) 
include $(SRCS:%.cpp=./dep/%.d)